<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="/X-admin/css/font.css">
    <link rel="stylesheet" href="/X-admin/css/login.css">
    <link rel="stylesheet" href="/X-admin/css/xadmin.css">
    <script src="/js/jquery-3.6.0.min.js"></script>
    <script src="/js/myAjax.js"></script>
    <script src="/X-admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/X-admin/js/xadmin.js"></script>
    <script src="../../js/myAjax.js"></script>
    <script src="../../js/x-member-add.js"></script>


<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>用户名</label>
                <div class="layui-input-inline">
                    <input type="text" id="username" name="username" required="" lay-verify="username"
                           autocomplete="off"
                           class="layui-input"></div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="email" class="layui-form-label">
                    <span class="x-red">*</span>邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" id="email" name="email" required="" lay-verify="email" autocomplete="off"
                           class="layui-input"></div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>将会成为您唯一的登入名
                </div>
            </div>
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>性别</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" title="男" value="男" class="layui-input">
                    <input type="radio" name="sex" title="女" value="女" class="layui-input">
                    <input type="radio" name="sex" title="保密" value="保密" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="username" class="layui-form-label">
                    <span class="x-red">*</span>爱好</label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="hobby" title="c语言" lay-skin="primary" class="layui-input">
                    <input type="checkbox" name="hobby" title="java" lay-skin="primary" class="layui-input">
                    <input type="checkbox" name="hobby" title="python" class="layui-input">
                    <input type="checkbox" name="hobby" title="c++" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>状态</label>
                <div class="layui-input-inline">
                    <select id="enable" name="enable" class="valid">
                        <option value="1">启用</option>
                        <option value="0">停用</option>
                    </select>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <label for="birthday" class="layui-form-label">
                    <span class="x-red">*</span>生日</label>
                <div class="layui-input-inline">
                    <input class="layui-input" autocomplete="off" placeholder="生日" name="birthday" id="birthday">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*</span>
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit="">新增</button>
            </div>
        </form>
    </div>
</div>
<script>layui.use(['laydate', 'form', 'layer'],
    function () {
        $ = layui.jquery;
        var form = layui.form,
            layer = layui.layer;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birthday' //指定元素
            , trigger: "click"
        });
        //自定义验证规则
        form.verify({
            nikename: function (value) {
                if (value.length < 5) {
                    return '昵称至少得5个字符啊';
                }
            },
            pass: [/(.+){6,12}$/, '密码必须6到12位'],
            repass: function (value) {
                if ($('#L_pass').val() != $('#L_repass').val()) {
                    return '两次密码不一致';
                }
            }
        });

        //监听提交
        form.on('submit(add)',
            function (data) {
                // console.log(data.field);
                data = data.field;
                // console.log(  $("input[name='sex']:checked").attr("title"));
                data.sex = $("input[name='sex']:checked").attr("title");
                let hobby = [];
                $('input:checkbox[name=hobby]:checked').each(function (index, dom) {
                    // let hobby = data.hobby;
                    // let hobbys = hobby.split(",");
                    // for (let i = 0; i < hobbys.length; i++) {
                    //     if (hobbys[i] == dom.title)
                    //         $(this).attr('checked', true);
                    // }
                    hobby.push(dom.title);

                });
                data.hobby = hobby.toLocaleString();

                console.log(data);
                // return ;
                let result = myAjax("/back/user/add", data, "post");
                //发异步，把数据提交给php
                if (result.code == 0) {
                    layer.alert("新增成功", {
                            icon: 6
                        },
                        function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });

                } else {
                    layer.alert("新增失败", {icon: 2});
                }

                return false;
            });

    });</script>
<script>var _hmt = _hmt || [];
(function () {
    var hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>

</html>